/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import model.SituacaoQuartoModel;

/**
 *
 * @author WELISSON
 */
public class SituacaoQuartoDAO extends GenericDAO{
    
    public void salvar(SituacaoQuartoModel situacao) throws SQLException {
        String insert = "INSERT INTO situacao_quartos(codigo, descricao) "
                + "VALUES(?,?)";
        
        save(insert, situacao.getCodigo(), situacao.getDescricao());
    }
    
    public int salvarRetornarId(SituacaoQuartoModel situacao) throws SQLException {
        String insert = "INSERT INTO situacao_quartos(codigo, descricao) "
                + "VALUES(?,?)";
        return saveReturnId(insert, situacao.getCodigo(), situacao.getDescricao());
    }
 
    public void alterar(SituacaoQuartoModel situacao) throws SQLException {
        String update = "UPDATE situacao_quartos " +
                "SET codigo = ?, descricao = ? " +
                "WHERE matricula = ?";
        update(update, situacao.getCodigo(), situacao.getDescricao());
    }
 
    public void excluir(String id) throws SQLException {
        String delete = "DELETE FROM situacao_quartos WHERE codigo = ?";
        delete(delete, id);
    }
    public List<SituacaoQuartoModel> findSituacaoQuarto() throws SQLException{
        
        List<SituacaoQuartoModel> situacoes = new ArrayList<SituacaoQuartoModel>();
 
        String select = "SELECT * FROM situacao_quartos";
 
        PreparedStatement stmt = 
            getConn().prepareStatement(select);
             
        ResultSet rs = stmt.executeQuery();
 
        while (rs.next()) {
            SituacaoQuartoModel situacao = new SituacaoQuartoModel();
            situacao.setCodigo(rs.getString("codigo"));
            situacao.setDescricao(rs.getString("descricao"));
            
            situacoes.add(situacao);
        }
 
        rs.close();
        stmt.close();
 
        return situacoes;
    }
 
    public List<SituacaoQuartoModel> findByArgument(String argumento, String pesquisa) throws SQLException{
        
        List<SituacaoQuartoModel> situacoes = new ArrayList<SituacaoQuartoModel>();
        
        String select = "SELECT * FROM situacao_quartos WHERE ? = ?";
        PreparedStatement stmt = 
            getConn().prepareStatement(select);
             
        stmt.setString(1, argumento);
        stmt.setString(2, pesquisa);
        ResultSet rs = stmt.executeQuery();
 
        while (rs.next()) {
            SituacaoQuartoModel situacao = new SituacaoQuartoModel();
            situacao.setCodigo(rs.getString("codigo"));
            situacao.setDescricao(rs.getString("descricao"));
        }
 
        rs.close();
        stmt.close();
 
        return situacoes;
    }
    
}
